using System;
using System.Collections.Generic;
using System.Text;

namespace AIFSContentManagementSystem
{
    using AIFSDataAccessLayer;

    public sealed class ManagerContextRepository
    {
        /// <summary>
        /// Gets the manager context with default data execution context. Enables to create the context
        /// with or without support of transaction.
        /// </summary>
        public static IManagerContext GetManagerContext(bool supportTransaction)
        {
            IDataExecutionContext dataExecutionContext = null;

            if (supportTransaction)
                dataExecutionContext = new TransactionalExecutionContext();
            else
                dataExecutionContext = new SimpleExecutionContext();

            dataExecutionContext.ConnectionProvider = new AIFSCMSDataAccessLayer.DefaultConnectionProvider();

            IManagerContext managerContext = new DefaultManagerContext();
            managerContext.DataExecutionContext = dataExecutionContext;

            return managerContext;
        }

        /// <summary>
        /// Gets the manager context with default data execution context. Does not support transaction.
        /// </summary>
        /// <returns></returns>
        public static IManagerContext GetDefault(bool supportTransaction)
        {
            IDataExecutionContext dataExecutionContext = null;

            if (supportTransaction)
                dataExecutionContext = new TransactionalExecutionContext();
            else
                dataExecutionContext = new SimpleExecutionContext();

            dataExecutionContext.ConnectionProvider = new AIFSCMSDataAccessLayer.DefaultConnectionProvider();

            IManagerContext managerContext = new DefaultManagerContext();
            managerContext.DataExecutionContext = dataExecutionContext;

            return managerContext;
        }
    }
}
